package report

import (
	"github.com/gin-gonic/gin"
	"github.com/lab-online/internal/report/domain"
	"github.com/lab-online/internal/report/export"
	"github.com/lab-online/internal/report/handler"
	"github.com/lab-online/internal/report/infra/mq"
	"github.com/lab-online/internal/report/infra/repository"
	"github.com/lab-online/internal/report/interface/rest"
	"github.com/lab-online/pkg/auth"
)

type Route struct {
	rest.ReportHandler
	auth auth.Middleware
}

var (
	NewRepository = repository.New
	NewMQ         = mq.New
	NewDomain     = domain.New
	NewExport     = export.New
)

func NewRoute(authMiddleware auth.Middleware, d domain.ReportDomain) *Route {
	h := handler.New(d)
	return &Route{h, authMiddleware}
}

func (r *Route) Register(router *gin.RouterGroup) {
	report := router.Group("/reports")

	report.GET("", r.auth(auth.RoleAll), handler.SearchReportValidator, r.SearchReport)
	report.GET("/:id", r.auth(auth.RoleAll), handler.GetReportValidator, r.GetReport)

	// report.PATCH("/:id/score", r.auth(auth.RoleAll), r.UpdateScore)
	report.GET("/:id/subscribe", r.auth(auth.RoleAll), handler.SubscribeReportValidator, r.SubscribeReport)
}
